﻿using Dsl.Ped.Editor.Helpers;
using NUnit.Framework;

namespace DSLPedUtilsTest.Utils
{
    /// <summary>
    /// Tests of the <see cref="XmlHelper"/> class
    /// </summary>
    [TestFixture]
    public class XmlUtilsTest
    {
        private const string NoEncodingFile = "TestingFiles/ProjNoEncoding.xml";
        private const string Utf8File = "TestingFiles/ProjUTF8.xml";
        private const string Utf16File = "TestingFiles/ProjUTF16.xml";
        private const string NonExistingFile = "TestingFiles/Nonexisting.xml";
        private const string MessFile = @"kda fjak \/*$adfkjf*=-)(*&^^%%$$@!.xml";
        private const string Utf8NoNamespaceFile = "TestingFiles/ProjUTF8NoNamespace.xml";
        private const string NoXMLContentFile = "TestingFiles/NoXMLContent.txt";

        [SetUp]
        public void SetUpForEachTest()
        {
            // Not used section
        }

        [Test]
        public void GetXmlDocumentNoEncodingTest()
        {
            var xmlDocument = XmlHelper.GetXmlDocument(NoEncodingFile);
            Assert.NotNull(xmlDocument);
        }

        [Test]
        public void GetXmlDocumentUTF8Test()
        {
            var xmlDocument = XmlHelper.GetXmlDocument(Utf8File);
            Assert.NotNull(xmlDocument);
        }

        [Test]
        public void GetXmlDocumentUTF16Test()
        {
            var xmlDocument = XmlHelper.GetXmlDocument(Utf16File);
            Assert.NotNull(xmlDocument);
        }

        [Test]
        public void GetXmlDocumentNonExistingTest()
        {
            var xmlDocument = XmlHelper.GetXmlDocument(NonExistingFile);
            Assert.IsNull(xmlDocument);
        }

        [Test]
        public void GetXmlDocumentMessTest()
        {
            var xmlDocument = XmlHelper.GetXmlDocument(MessFile);
            Assert.IsNull(xmlDocument);
        }

                [Test]
        public void GetXmlDocumentNoXMLContentTest()
        {
            var xmlDocument = XmlHelper.GetXmlDocument(NoXMLContentFile);
            Assert.IsNull(xmlDocument);
        }

        [Test]
        public void GetXmlNamespaceNoEncodingTest()
        {
            var xmlNamespace = XmlHelper.GetXmlNamespace(NoEncodingFile);
            Assert.AreEqual("http://Proj", xmlNamespace);
        }

        [Test]
        public void GetXmlNamespaceUTF8Test()
        {
            var xmlNamespace = XmlHelper.GetXmlNamespace(Utf8File);
            Assert.AreEqual("http://Proj", xmlNamespace);
        }

        [Test]
        public void GetXmlNamespaceUTF16Test()
        {
            var xmlNamespace = XmlHelper.GetXmlNamespace(Utf16File);
            Assert.AreEqual("http://Proj", xmlNamespace);
        }

        [Test]
        public void GetXmlNamespaceUTF8NoNamespaceTest()
        {
            var xmlNamespace = XmlHelper.GetXmlNamespace(Utf8NoNamespaceFile);
            Assert.AreEqual(string.Empty, xmlNamespace);
        }
    }
}
